package com.elibrary;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import com.actionbarsherlock.app.SherlockListFragment;
import nimo.elibrary.json.model.book.Book;

/**
 * Created with IntelliJ IDEA.
 * User: Enkuso
 * Date: 1/23/13
 * Time: 11:29 AM
 * To change this template use File | Settings | File Templates.
 */
public class HistoryFragment2 extends SherlockListFragment {
    Book[] books;
    HistorylistAdapter adapter;
    int mNum;

    public HistoryFragment2() {

    }

    public HistoryFragment2(int num, Book[] books) {
        // Supply num input as an argument.
        Bundle args = new Bundle();
        args.putInt("num", num);
        this.setArguments(args);
        this.books = books;
        setRetainInstance(true);
    }

    /**
     * When creating, retrieve this instance's number from its arguments.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mNum = getArguments() != null ? getArguments().getInt("num") : 1;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        adapter = new HistorylistAdapter(getActivity(),
                R.layout.history_list_item2, books);
        setListAdapter(adapter);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.history, container, false);
        return v;
    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        ((BaseActivity)getSherlockActivity()).gotoBookDetail(v,(String)v.getTag());
    }

    @Override
    public void onResume() {
        super.onResume();
        ((BaseActivity)getSherlockActivity()).currentFragment = Constants.FRAGMENT_BOOKMARK;
    }

    public void setBooks(Book[] books) {
        this.books = books;
    }
}
